package com.enbatis.mybatisplugs.controller;

import com.enbatis.mybatisplugs.commons.sql.Wrapper;
import com.enbatis.mybatisplugs.service.SysRoleRelResourceService;
import com.enbatis.mybatisplugs.base.BaseController;
import com.enbatis.mybatisplugs.commons.utils.ResultReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.enbatis.mybatisplugs.entity.SysRoleRelResource;


import java.util.List;

@RestController
@RequestMapping("v1/sys_role_rel_resource")
public class SysRoleRelResourceController extends BaseController {

@Autowired
private SysRoleRelResourceService sysRoleRelResourceService;


    @PostMapping("/add")
    public ResultReturn<SysRoleRelResource> add(SysRoleRelResource sysRoleRelResource){
        return  success(sysRoleRelResourceService.insert(sysRoleRelResource));
    }



    @PostMapping("/add_role_resource")
    public ResultReturn<Boolean> addRoleResource(@RequestParam("roleId")Long roleId,@RequestParam("resourceIds")Long[] resourceIds){
        return  success(sysRoleRelResourceService.addRoleResource(roleId,resourceIds,getAccount()));
    }


    @DeleteMapping("/delete")
    public ResultReturn<Integer> delete(@RequestParam("id") Long id){
        return success(sysRoleRelResourceService.deleteById(id));
    }


    @PutMapping("/{id}")
    public  ResultReturn<Integer> update(@PathVariable("id") Long id,SysRoleRelResource sysRoleRelResource){
        sysRoleRelResource.setId(id);
        return success(sysRoleRelResourceService.updateById(sysRoleRelResource));
    }


    @GetMapping("/{id}")
    public ResultReturn<SysRoleRelResource> get(@PathVariable("id") Long id) {
        return success(sysRoleRelResourceService.getById(id));
    }


    @GetMapping("/list")
    public ResultReturn<List<SysRoleRelResource>> getList(SysRoleRelResource sysRoleRelResource){
        return success(sysRoleRelResourceService.list(new Wrapper<>(sysRoleRelResource)));
    }

}
